﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using ConfApp.Models;
using ConfApp.Services;

namespace ConfApp.ViewModels
{
    public class PodcastInfoViewModel : ViewModel 
    {
        private readonly Podcast _podcast;
        
        public PodcastInfoViewModel(
            Podcast podcast, 
            INavigationService navigationService)
            : base(navigationService)
        {
            _podcast = podcast;
        }

        public Podcast Podcast
        {
            get { return _podcast; }
        }

        public int ID { get { return Podcast.ID; } }
        public string Title { get { return Podcast.Title; } }
        public string Details { get { return Podcast.Details; } }
        public string Author { get { return Podcast.Author; } }

        public Uri Url
        {
            get
            {
                return new Uri(Podcast.Url);
            }
        }

        public DateTime PublishingDate { get { return Podcast.Date; } }

        public string Info
        {
            //get
            //{

            //    var dt = Time.Now - PublishingDate;
            //    if (dt.TotalMinutes < 1)
            //    {
            //        return string.Format("{0}, malopre", Author);
            //    }
            //    if (dt.TotalMinutes < 60)
            //    {
            //        return string.Format("{0}, pre {1} min", Author, (int)dt.TotalMinutes);
            //    }
            //    else if (dt.TotalHours < 24)
            //    {
            //        return string.Format("{0}, pre {1} h", Author, (int)dt.TotalHours);
            //    }
            //    return string.Format("{0} @ {1:dd.MM.yyyy.}", Author, PublishingDate);
            //}
            get
            {

                var dt = Time.Now - PublishingDate;
                if (dt.TotalMinutes < 1)
                {
                    return string.Format("malopre");
                }
                if (dt.TotalMinutes < 60)
                {
                    return string.Format("pre {1} min", Author, (int)dt.TotalMinutes);
                }
                else if (dt.TotalHours < 24)
                {
                    return string.Format("pre {1} h", Author, (int)dt.TotalHours);
                }
                return string.Format("{1:dd.MM.yyyy.}", Author, PublishingDate);
            }
        }

        public override void IsBeingActivated()
        {

        }
    }
}
